home *** CD-ROM | disk | FTP | other *** search
/ Run Magazine ReRun 1985 Summer / rerun-1985-summer-side-b.d64 / play ball (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  6KB  |  262 lines

  1. 10 dima(20,6),b(20,6),c(20,6),n$(20),a$(20),b$(20),m(6),t(6),u(6)
  2. 20 np=0:ad=0:na=0
  3. 30 poke53280,11:poke53281,11:printchr$(5)
  4. 100 rem ***************** menu ****************
  5. 110 printchr$(147):print:printtab(12)"softball stats"
  6. 120 print
  7. 130 print:print"    1   load previous stats"
  8. 140 print:print"    2   add new data"
  9. 150 print:print"    3   sort and display stats"
  10. 160 print:print"    4   save new data"
  11. 170 print:print"    5   add players"
  12. 180 print:print"    6   print stats"
  13. 190 print:print"    7   quit program"
  14. 200 print:print
  15. 210 c=0:input"         enter your choice";c
  16. 220 ifc<1orc>7then210
  17. 230 oncgosub1000,2000,3000,4000,5000,8200,11000
  18. 240 goto100
  19. 1000 rem ********* read old data from tape or disk *********
  20. 1005 printchr$(147):gosub9800:iftd$="t"then1011
  21. 1010 open2,8,2,"0:softball "+gn$+",s,r":goto1015
  22. 1011 open2,1,0,"softball"
  23. 1015 input#2,gm
  24. 1020 printchr$(147):print"softball stats through game #";gm:print
  25. 1030 gosub10000
  26. 1035 na=np
  27. 1040 np=np+1:input#2,n$(np)
  28. 1050 ifn$(np)="end"thennp=np-1:goto1070
  29. 1060 goto1040
  30. 1070 fori=na+1tonp
  31. 1080 forj=1to5
  32. 1090 input#2,a(i,j)
  33. 1100 nextj
  34. 1110 input#2,a$(i)
  35. 1130 printn$(i);
  36. 1140 x=8
  37. 1150 fork=1to5
  38. 1160 printtab(x)a(i,k);
  39. 1170 x=x+5
  40. 1180 nextk
  41. 1182 ifa$(i)="1.000"thenx=x-1
  42. 1185 printtab(x+1)a$(i)
  43. 1190 nexti:close2
  44. 1192 fori=1tonp:forj=1to5
  45. 1194 c(i,j)=a(i,j)
  46. 1196 next:next
  47. 1200 gosub6000:gosub6100
  48. 1205 iftd$="d"then1230
  49. 1210 print:print:printtab(9)"*** turn off tape ***"
  50. 1220 ifpeek(192)<>0then1220
  51. 1230 gosub9500
  52. 1240 return
  53. 2000 rem *********** input this weeks data ***********
  54. 2005 printchr$(147):print"      input new data":print:print
  55. 2007 ad=1
  56. 2010 fori=1tonp
  57. 2020 printn$(i)
  58. 2030 gosub8500
  59. 2060 gosub2500
  60. 2070 print
  61. 2080 nexti
  62. 2090 gosub10000:gosub8000
  63. 2100 rem check for errors
  64. 2105 print:printtab(12)"check for errors"
  65. 2110 print:print"    hit 'e' to correct input errors"
  66. 2120 getk$:ifk$=""then2120
  67. 2130 ifk$="e"thengosub7000
  68. 2140 printchr$(147):print:print"    computing..."
  69. 2165 rem *** add new data to old
  70. 2170 fori=1tonp
  71. 2180 forj=1to5
  72. 2190 b(i,j)=b(i,j)+a(i,j)
  73. 2200 nextj
  74. 2210 gosub2500
  75. 2230 nexti
  76. 2240 gosub8800:gosub6000
  77. 2250 return
  78. 2500 rem *************** compute avg ***************
  79. 2510 ifb(i,1)=0thenb(i,6)=0:goto2550
  80. 2520 b(i,6)=b(i,2)/b(i,1)
  81. 2530 b(i,6)=int(b(i,6)*1000+.5)/1000
  82. 2540 ifb(i,6)=1thenb$(i)="1.000":goto2600
  83. 2550 ifb(i,6)=0thenb$(i)=" .000":goto2600
  84. 2560 b$(i)=str$(b(i,6)):l=len(b$(i))
  85. 2570 ifl=3thenb$(i)=b$(i)+"00":goto2600
  86. 2580 ifl=4thenb$(i)=b$(i)+"0"
  87. 2600 return
  88. 3000 rem ************* shell sort ********************
  89. 3005 ifad=0thenad=1:gosub2170
  90. 3007 gosub9000
  91. 3008 printchr$(147);:print"  computing...."
  92. 3010 n=np
  93. 3020 g=int(n/2)
  94. 3030 ifg=0then3160
  95. 3040 fori=1ton-g
  96. 3050 ifb(i,s)>=b(i+g,s)then3100
  97. 3060 forj=1to6:t(j)=b(i,j):u(j)=a(i,j):next
  98. 3062 t$=n$(i):tb$=b$(i)
  99. 3070 forj=1to6:b(i,j)=b(i+g,j):a(i,j)=a(i+g,j):next
  100. 3072 n$(i)=n$(i+g):b$(i)=b$(i+g)
  101. 3080 forj=1to6:b(i+g,j)=t(j):a(i+g,j)=u(j):next
  102. 3082 n$(i+g)=t$:b$(i+g)=tb$
  103. 3090 e=1
  104. 3100 next
  105. 3110 ife=0then3140
  106. 3120 e=0
  107. 3130 goto3030
  108. 3140 g=int(g/2)
  109. 3150 goto3030
  110. 3160 printchr$(147):print:gosub10000
  111. 3165 print:gosub8000:gosub8800
  112. 3170 gosub6000:gosub6100
  113. 3180 print:gosub9500:return
  114. 4000 rem ******** save new stats to tapeor disk *********
  115. 4002 printchr$(147):print:print
  116. 4005 gosub9800:iftd$="t"then4011
  117. 4010 open2,8,2,"0:softball "+gn$+",s,w":goto4015
  118. 4011 open2,1,1,"softball"
  119. 4015 print#2,ga
  120. 4020 fori=1tonp
  121. 4030 print#2,n$(i)
  122. 4040 next
  123. 4045 print#2,n$(np+1)
  124. 4050 fori=1tonp
  125. 4060 forj=1to5
  126. 4070 print#2,b(i,j)
  127. 4080 nextj
  128. 4085 print#2,b$(i)
  129. 4090 nexti
  130. 4100 close2
  131. 4102 print:print:printtab(12)"new stats saved"
  132. 4104 iftd$="d"then4110
  133. 4105 print:printtab(13)"turn off tape"
  134. 4106 ifpeek(192)<>0then4106
  135. 4110 print:gosub9500:return
  136. 5000 rem *********add players (or start year) **********
  137. 5010 printchr$(147):print:print"    enter 'end' after last player":print
  138. 5020 np=np+1
  139. 5030 input"name";n$(np)
  140. 5035 iflen(n$(np))>8thenn$(np)=left$(n$(np),8)
  141. 5040 ifn$(np)="end"thennp=np-1:goto5100
  142. 5050 forj=1to6
  143. 5060 a(np,j)=0
  144. 5070 next
  145. 5080 b$(np)=" .000"
  146. 5090 print:goto5020
  147. 5100 return
  148. 6000 rem ************ team totals (m) **************
  149. 6010 fori=1to5:m(i)=0:next:print
  150. 6020 forj=1to5
  151. 6030 fori=1tonp
  152. 6040 m(j)=m(j)+c(i,j)
  153. 6050 next
  154. 6060 next
  155. 6070 ifm(1)=0thenm(6)=0:goto6093
  156. 6080 m(6)=m(2)/m(1)
  157. 6090 m(6)=int(m(6)*1000+.5)/1000
  158. 6092 ifm(6)=1thenm$="1.000":goto6099
  159. 6093 ifm(6)=0thenm$=" .000":goto6099
  160. 6095 m$=str$(m(6)):l=len(m$)
  161. 6097 ifl=3thenm$=m$+"00":goto6099
  162. 6098 ifl=4thenm$=m$+"0"
  163. 6099 return
  164. 6100 x=8
  165. 6110 print"totals";
  166. 6120 forj=1to5
  167. 6130 printtab(x)m(j);
  168. 6140 x=x+5
  169. 6150 next
  170. 6155 printtab(x)m$
  171. 6160 return
  172. 7000 rem ************ error correction ************
  173. 7010 printchr$(147):print:printtab(12)"error correction":print:print
  174. 7020 pf=0:input"name of player";c$:print
  175. 7030 fori=1tonp
  176. 7040 ifc$<>n$(i)then7060
  177. 7050 pf=1:gosub8500
  178. 7060 nexti
  179. 7065 ifpf=0thenprint"player not found, try again":print:goto7020
  180. 7070 print:input"more corrections (y/n)";mc$
  181. 7080 ifmc$="n"thenreturn
  182. 7090 ifmc$="y"then7010
  183. 7100 goto7070
  184. 8000 rem ********** print stats (screen) ***********
  185. 8010 fori=1tonp
  186. 8020 printn$(i);
  187. 8030 x=8
  188. 8040 forj=1to5
  189. 8050 printtab(x)b(i,j);
  190. 8060 x=x+5
  191. 8070 next
  192. 8072 printtab(x)b$(i)
  193. 8080 next
  194. 8090 return
  195. 8200 rem ************ stats to printer ************
  196. 8210 ifad=0thenad=1:gosub2170
  197. 8215 printchr$(147):input"stats through game #";gn
  198. 8220 print:print"   turn printer on, set pitch, margins"
  199. 8225 print:print"and line spacing.":print:print
  200. 8230 gosub9500
  201. 8240 open4,4:cmd4
  202. 8245 print"softball stats through game #";gn
  203. 8250 print
  204. 8260 print"name"spc(8)"ab"spc(6)"h"spc(7)"r"spc(7)"rbi"spc(5)"bb"spc(7)"avg"
  205. 8270 print
  206. 8280 fori=1tonp
  207. 8285 zz=11-len(n$(i))
  208. 8290 printn$(i);spc(zz);
  209. 8300 forj=1to5
  210. 8305 zz=7-(len(str$(b(i,j))))
  211. 8310 printb(i,j);spc(zz);
  212. 8320 nextj
  213. 8330 printb$(i)
  214. 8340 nexti
  215. 8350 print:print"totals     ";
  216. 8360 forj=1to5
  217. 8365 zz=7-(len(str$(m(j))))
  218. 8370 printm(j);spc(zz);
  219. 8380 next
  220. 8390 printm$
  221. 8400 print#4:close4
  222. 8410 return
  223. 8500 rem ************** input stats **************
  224. 8510 input"abs";b(i,1)
  225. 8520 input"hits";b(i,2)
  226. 8530 input"runs";b(i,3)
  227. 8540 input"rbis";b(i,4)
  228. 8550 input"walks";b(i,5)
  229. 8570 return
  230. 8800 rem ****** set c(x,x) before totals******
  231. 8810 fori=1tonp:forj=1to5
  232. 8820 c(i,j)=b(i,j)
  233. 8830 next:next
  234. 8840 return
  235. 9000 rem *************** sort menu ***************
  236. 9010 printchr$(147):print:print "which category do you want to sort by?"
  237. 9020 print
  238. 9030 print:print"      1   at bats"
  239. 9040 print:print"      2   hits"
  240. 9050 print:print"      3   runs"
  241. 9060 print:print"      4   rbis"
  242. 9070 print:print"      5   walks"
  243. 9080 print:print"      6   average"
  244. 9090 print:print:print
  245. 9100 input"   enter your choice";s
  246. 9110 ifs<1ors>6then9100
  247. 9120 return
  248. 9500 rem *************** get key *************
  249. 9510 print:printtab(15)"hit a key"
  250. 9520 getk$:ifk$=""then9520
  251. 9530 return
  252. 9800 rem *** get tape or disk input ***
  253. 9810 input"tape or disk (t/d)";td$
  254. 9820 iftd$<>"d"andtd$<>"t"then9810
  255. 9840 print:input"stats through game number";gn$:ga=val(gn$)
  256. 9850 return
  257. 10000 rem ************** print headings ************
  258. 10010 print"name";tab(9)"ab";tab(14)"h";tab(19)"r";tab(23)"rbi";tab(29)"bb";
  259. 10020 printtab(35)"avg"
  260. 10030 return
  261. 11000 printchr$(147):end:rem ****** quit ******
  262.